package com.hama.iotrust.common.mybatis.dialect;

public class Dialect {

    public boolean supportsLimit() {
        return false;
    }

    public boolean supportsLimitOffset() {
        return supportsLimit();
    }

    /**
     * 将SQL变成分页SQL语句,直接使用offset,limit的值作为占位符.</br> 源代码为: getLimitString(sql, offset, limit)
     */
    public String getLimitString(String sql, int offset, int limit) {
        return getLimitString(sql, offset, Integer.toString(offset), limit, Integer.toString(limit));
    }

    /**
     * 将SQL变成分页SQL语句,提供将offset及limit使用占位符(placeholder)替换.
     * 
     * <pre>
     * 如MySQL
     * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
     * select * from user limit :offset,:limit
     * </pre>
     * 
     * @return 包含占位符的分页sql
     */
    public String getLimitString(String sql, int offset, String offsetPlaceholder, int limit, String limitPlaceholder) {
        throw new UnsupportedOperationException("paged queries not supported");
    }

    public String getCountSql(String sql) {
        StringBuffer countSql = new StringBuffer(sql.length() + 100);
        countSql.append("select count(1) from (").append(sql).append(") t_ibatis_pagination");
        return countSql.toString();
    }
}
